/// <reference path="../src/plat/IPlat.ts" />

namespace mgp.plat {

    export var type = PlatType.web;

    /** 开发者不需要手动调用 */
    export function init() {
        // 这里要判断是使用什么平台的platsdk
        if (!window || !window.navigator) return;
        let u = window.navigator.userAgent || '';
        if (u.indexOf('OPPO') > -1 && u.indexOf('MiniGame') > -1) {
            // oppo
            type = PlatType.oppo;
        } else if (u.indexOf('VVGame') > -1) {
            // vivo
            type = PlatType.vivo;
        } else if (u.indexOf("MiniGame") > -1 && window['qq']) {
            // qq
            type = PlatType.qq;
        } else if (u.indexOf('OPPO') == -1 && u.indexOf("MiniGame") > -1 && window['wx']) {
            if (window['tt']) {
                // tt
                type = PlatType.tt;
            } else if (window['bl']) {
                // bili
                type = PlatType.bili;
            } else {
                // wx
                type = PlatType.wx;
            }
        } else if (window['mz']) {
            // mz
            type = PlatType.mz;
        } else if (u.indexOf('QuickGame') > -1 && !window['mz']) {
            // xm
            type = PlatType.xm;
        } else if (u.indexOf("SwanGame") > -1) {
            // bd
            type = PlatType.bd;
        } else if (u.indexOf('AlipayMiniGame') > -1 && window['my']) {
            // alipay
            type = PlatType.ali;
        } else {
            // web
            type = PlatType.web;
        }
    }

}

if (window) {
    if (window['mgp']) {
        window['mgp'].plat = mgp.plat;
        window['mgp'].utils = mgp.utils;
    } else {
        window['mgp'] = mgp;
    }

    mgp.plat.init();
}